﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FileSystem.Models;

namespace FileSystem.Services.IServices {
    /// <summary>
    /// 物理磁盘块存储接口
    /// </summary>
    public interface IPhysicalDiskBlockStorage {
        /// <summary>
        /// 初始化物理磁盘块存储
        /// </summary>
        Task InitializeAsync();

        /// <summary>
        /// 物理磁盘块存储是否已经初始化
        /// </summary>
        bool IsInitialized();

        /// <summary>
        /// 增加物理磁盘块
        /// </summary>
        /// <param name="physicalDiskBlock">要删除的物理磁盘块</param>
        Task AddAsync(PhysicalDiskBlock physicalDiskBlock);

        /// <summary>
        /// 删除物理磁盘块
        /// </summary>
        /// <param name="physicalDiskBlock">要删除的物理磁盘块</param>
        Task RemoveAsync(PhysicalDiskBlock physicalDiskBlock);

        /// <summary>
        /// 修改物理磁盘块内容
        /// </summary>
        /// <param name="physicalBlockNumber">要修改的物理块块号</param>
        /// <param name="newContent">新内容</param>
        Task ModifyContent(int physicalBlockNumber, string newContent);

        /// <summary>
        /// 根据物理块号获得一个物理磁盘块
        /// </summary>
        /// <param name="physicalBlockNumber">物理块号</param>
        Task<PhysicalDiskBlock> GetPhysicalDiskBlock(int physicalBlockNumber);

        /// <summary>
        /// 获得所有物理磁盘块
        /// </summary>]
        Task<IList<PhysicalDiskBlock>> GetPhysicalDiskBlocks();

        /// <summary>
        /// 判断物理磁盘块是否存在
        /// </summary>
        /// <param name="physicalBlockNumber">物理块号</param>
        Task<bool> Exist(int physicalBlockNumber);
    }

    /// <summary>
    /// 物理磁盘块存储常量
    /// </summary>
    public static class PhysicalDiskBlockStorageConstants
    {
        /// <summary>
        /// 默认的物理磁盘块数据库版本号。
        /// </summary>
        public const int DefaultVersion = 0;

        /// <summary>
        /// 物理磁盘块数据库版本号。
        /// </summary>
        public const int Version = 1;

        /// <summary>
        /// 物理磁盘块数据库版本号键。
        /// </summary>
        public const string VersionKey = nameof(PhysicalDiskBlockStorageConstants) +
            "." + nameof(Version);
    }
}